/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: OnConnection.java   2020-10-07 23-42-54
 * Author: Evan
 */
package cn.datacare.orm.source;

import cn.datacare.orm.connection.ConnectionSource;
import cn.datacare.orm.manager.impl.SQLManager;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-10-07 23-42-54
 * @since V1.0
 */
public abstract class OnConnection<T> {
    protected SQLManager sqlManager = null;

    /**
     * 回调函数
     * @param conn
     * @return
     * @throws SQLException
     */
    public abstract T call(Connection conn) throws SQLException;
    /**
     * 获得数据库连接，默认返回master
     * @param cs
     * @return
     */
    public Connection getConn(ConnectionSource cs){
        return cs.getMaster();
    }
    public SQLManager getSqlManager() {
        return sqlManager;
    }
    public void setSqlManager(SQLManager sqlManager) {
        this.sqlManager = sqlManager;
    }
}
